<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        canvas {
            position: absolute;
            z-index: 2;
            border: 1px solid black;
        }
        .ggk{
            width: 800px;
            height: 400px;
            font-size: 30px;
            text-align: center;
            line-height: 400px;
            overflow: hidden;
            position: absolute;
            left: 0;
            top: 0;
            user-select: none;
            z-index: 1;
        }
    </style>
</head>

<body>
    <div class="ggk">恭 喜 中 奖</div>
    <canvas width="800" height="400"></canvas>
    <script>
        let canvas = document.querySelector('canvas');
        let ctx = canvas.getContext('2d');
        let ggk = document.querySelector('.ggk');
        let isDraw = false;

        if(Math.random()<0.1){
            ggk.innerHTML = '恭 喜 中 奖';
        }
        else{
            ggk.innerHTML = '谢 谢 惠 顾';
        }

         let img = document.createElement('img');
         img.src = '../00-assets/imgs/s11.jpg';

         img.onload = function(){
            ctx.drawImage(img, 0, 0,1837,1080);
         }

         canvas.onmousedown = (event)=>{
            isDraw = true;

         }

         canvas.onmouseup = ()=>{
            isDraw = false;
         }

         canvas.onmousemove = (event)=>{
            if(isDraw){
                console.log(123);
                let x = event.pageX;
                let y = event.pageY;
                
                ctx.globalCompositeOperation = 'destination-out';
                ctx.arc(x,y,20,0,Math.PI*2);
                ctx.fill();
            }
         }
    </script>
</body>

</html>